//
//  AppDelegate.m
//  PinGJByOwnerSide
//
//  Created by lantaiyuan on 2017/8/4.
//  Copyright © 2017年 lantaiyuan. All rights reserved.
//

#import "AppDelegate.h"
#import "YMTakePassengerViewController.h"
#import "SYDHomeViewController.h"

@interface AppDelegate ()<AMapLocationManagerDelegate>
@property (nonatomic, strong) SYDLocationManage *locationManager;//自定义高德
@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    
    [YMSaveTool setObject:@"current_device" forKey:Current_Device];
    NSString *uuid = [[UIDevice currentDevice]uuid];
    [YMSaveTool setObject:uuid forKey:Device_uuid];
    
    // 开启高德地图及定位
    [YMMaMapServices start];
    self.locationManager = [[SYDLocationManage alloc]init];
    
    // 1.创建窗口
    self.window = [[UIWindow alloc] init];
    self.window.backgroundColor = [UIColor whiteColor];
    self.window.frame = [UIScreen mainScreen].bounds;
    
    [self.window switchRootViewController];
//    self.window.rootViewController = [[YMNavigationController alloc] initWithRootViewController:[[SYDHomeViewController alloc] init]];
    
    // 键盘处理
    [IQKeyboardManager sharedManager].enable = YES;
    
    //4.设置状态栏颜色
    application.statusBarStyle = UIStatusBarStyleLightContent;
    
    //3.显示窗口
    [self.window makeKeyAndVisible];
    
    //监测bug
    //[Bugtags startWithAppKey:@"6f98d5bedb42d3e47d05afb46ee650e8" invocationEvent:BTGInvocationEventBubble];
    
    return YES;
}

#pragma mark - 申请通知权限
- (void)registerNotificationAuthor{
    
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {
        
        //创建设置
        UIUserNotificationSettings *setting = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
        
        [[UIApplication sharedApplication] registerUserNotificationSettings:setting];
    }
}
- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}


- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
}


- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}


- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

- (void)amapLocationManager:(AMapLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{
    switch (status) {
        case kCLAuthorizationStatusNotDetermined:// 用户还没决定
        {
            NSLog(@"用户还未决定");
        }
            break;
        case kCLAuthorizationStatusRestricted: // 访问受限
        {
            NSLog(@"访问受限");
        }
            break;
        case kCLAuthorizationStatusDenied:// 定位关闭时和对此APP授权为never时调用
        {
            if ([CLLocationManager locationServicesEnabled]) {
                NSLog(@"定位已开启，但被用户拒绝");
                
            } else {
                NSLog(@"定位关闭，不可用");
            }
        }
            break;
        case kCLAuthorizationStatusAuthorizedAlways:// 获取前后台定位授权
        {
            NSLog(@"获取前后台定位授权");
        }
            break;
        case kCLAuthorizationStatusAuthorizedWhenInUse:// 获得前台定位授权
        {
            NSLog(@"获取前台定位授权");
        }
            break;
            
        default:
            break;
    }
}

@end
